<script setup>
import { onMounted } from 'vue'
import * as echarts from 'echarts'

const zhexiantu = () => {
    // 找到用来展示 折线图 的元素
    const chartDom = document.getElementById('first');
    const myChart = echarts.init(chartDom);
    const option = {
        xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: 'line',
            smooth: true
            }
        ]
    };

    option && myChart.setOption(option);
}

const bingtu = () => {
    const dom = document.getElementById('second');
    const chart = echarts.init(dom);
    const option = {
            tooltip: {
                trigger: 'item'
            },
            legend: {
                top: '5%',
                left: 'center'
            },
            series: [
                {
                name: 'Access From',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                label: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    label: {
                    show: true,
                    fontSize: 40,
                    fontWeight: 'bold'
                    }
                },
                labelLine: {
                    show: false
                },
                data: [
                        { value: 1048, name: 'Search Engine' },
                        { value: 735, name: 'Direct' },
                        { value: 580, name: 'Email' },
                        { value: 484, name: 'Union Ads' },
                        { value: 300, name: 'Video Ads' }
                    ]
                }
            ]
    };

    option && chart.setOption(option);
}

onMounted( () => {
    zhexiantu();
    bingtu();
});

</script>

<template>
    <div class="container">
        <a-flex>
            <!-- 确定用来展示折线图的元素 -->
            <div id="first" style="height: 400px; width: 50%"></div>
            <!-- 确定用来展示饼图的元素 -->
            <div id="second" style="height: 400px; width: 50%"></div>
        </a-flex>
    </div>
</template>

<style scoped>

</style>